# Maintainer: David Runge <dvzrv@archlinux.org>

pkgname=openapi-generator
pkgver=7.1.0
pkgrel=1
pkgdesc="Generation of API client libraries, server stubs, documentation and configuration"
arch=(any)
url="https://github.com/openapitools/openapi-generator/"
license=(Apache-2.0)
_java_version=11
depends=(
  bash
  java-runtime=$_java_version
)
makedepends=(
  maven
  java-environment=$_java_version
  strip-nondeterminism
)
source=(
  $url/archive/v$pkgver/$pkgname-v$pkgver.tar.gz
  $pkgname.sh
)
sha512sums=('8133471f828f05b6eb5301d2f0cd66300db6e4b7ef6a28d0263c103f03d84c0a11a8d63b78e2cc6451d88dce8b08294663470f3eba11c763963245abcd6b96c0'
            '82a21b46b5340108a6cf54350c25e7d9e9fbb97a0837ff68dc74f7cf2b105c12c33a4cc20aa641e8a9e4034de3e62a3f9ca03f6f7e5dc4f37b3827dff41eac46')
b2sums=('60134e746da07ccd5ca23f7d39597b416e0a4eba982f5df238534373f49c0055ee879b9ce66844b1d441301197eb0be35042e6949eca0075ac4ae8d4b536033c'
        'c7bf34d415aeceba2816edd6010706a7b9b547c9240344e5431f3280a552c2b578de6fc3fc90b0640d4f91d655cc419aabe615b8946d6c82d71061afa65cc302')

prepare() {
  # set java version for wrapper script
  sed "s/JAVA_VERSION/$_java_version/" $pkgname.sh > $pkgname
}

build() {
  cd $pkgname-$pkgver
  mvn clean install
  # Timestamps in JAR files generated by Maven do not honour SOURCE_DATE_EPOCH
  # (https://cwiki.apache.org/confluence/pages/viewpage.action?pageId=74682318)
  find . -type f -iname "*.jar" -exec strip-nondeterminism --timestamp "$SOURCE_DATE_EPOCH" {} \;
}

package() {
  install -vDm 644 $pkgname-$pkgver/modules/$pkgname-cli/target/openapi-generator-cli.jar -t "$pkgdir/usr/share/java/$pkgname/"
  install -vDm 644 $pkgname-$pkgver/scripts/$pkgname-cli-completion.bash "$pkgdir/usr/share/bash/bash-completion/completions/openapi-generator"
  install -vDm 755 $pkgname -t "$pkgdir/usr/bin/"
  ln -svf "$pkgname" "$pkgdir/usr/bin/$pkgname-cli"
}
